<%@include file="/WEB-INF/pages/commons/commons.jsp"%>

<fmt:message var="title" key="blog_new_entry.jsp.title" scope="request"/>
<stripes:layout-render name="${_themePath}/basic-layout-without-navbar.jsp" _title="${title}">

    <stripes:layout-component name="_head">
        <jsecurity:hasPermission name="blog:newBlogEntry:${actionBean.blog.id}">
        <script type="text/javascript">
            $(document).ready(function() {
                $("#preview").click(function(){
                    //var form = this.form;
                    //var params = $(form).serializeArray();
                    //params.push({name:'blogEntry',value:''})

                    var params = new Array();
                    var previewContent = $("#previewContent").val();
                    params.push({name:'previewContent', value:previewContent});

                    $.post(
                        '<stripes:url beanclass="foo.bar.blog.web.action.registered.BlogsProfileActionBean" event="previewBlogEntry"/>',
                        params,
                        function(data){
                            $("#display").hide();
                            $("#display").html("<form><h2>Preview <a href='#' onclick='$(\"#display\").hide();'>close</a></h2><span class='radeox'>"+data+"</span><p/><p/><p/></form>");
                            $("#display").fadeIn();
                        });
                });


                $("#commandHelp").click(function(){
                    window.open('<stripes:url beanclass="foo.bar.blog.web.action.general.RenderEngineCommandHelpActionBean" />',
                            'commandHelp', 'status=1,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,height=500,width=500');
                    return false;
                });
            });
        </script>
        </jsecurity:hasPermission>
    </stripes:layout-component>

    <stripes:layout-component name="_content">

        <stripes:layout-component name="_topNav">
            <H1>Blog Management</H1>
            <UL class="gc-topnav-tabs">
                <LI>&nbsp;</LI>
            </UL>
        </stripes:layout-component>

        <div id="display">
        </div>


        <h2>New Entry</h2>
        <jsecurity:lacksPermission name="blog:newBlogEntry:${actionBean.blog.id}">
            No "blog:newBlogEntry:${actionBean.blog.id}" permission
        </jsecurity:lacksPermission>

        <jsecurity:hasPermission name="blog:newBlogEntry:${actionBean.blog.id}">
        <stripes:messages/>
        <stripes:errors globalErrorsOnly="true" />

        <div id="form">
        <stripes:form beanclass="foo.bar.blog.web.action.registered.BlogsProfileActionBean">

            <stripes:errors />

            <stripes:useActionBean beanclass="foo.bar.blog.web.action.general.BlogActionBean"
                                   event="allTags" alwaysExecuteEvent="true" executeResolution="false"
                                   validate="false" var="allTags"/>
            <input type="hidden" name="blogEntry" value=""/>
            <input type="hidden" name="blog" value="${actionBean.blog.id}"/>
            <input type="hidden" name="blogEntry.blog" value="${actionBean.blog.id}"/>

            <table width="100%">
                <tr>
                    <td><stripes:label name="blogEntry.name"/></td>
                    <td><stripes:text name="blogEntry.name"/></td>
                </tr>
                <tr>
                    <td><stripes:label name="blogEntry.description"/></td>
                    <td><stripes:textarea name="blogEntry.description" style="width:100%;"/></td>
                </tr>
                <tr>
                    <td><stripes:label name="blogEntry.tag"/></td>
                    <td>
                        <stripes:select name="blogEntry.tag" multiple="false">
                            <stripes:option label="" value="null"/>
                            <stripes:options-collection collection="${allTags.allTags}" label="name" value="id" />
                        </stripes:select>    
                    </td>
                </tr>
                <tr>
                    <td><stripes:label name="blogEntry.content"/></td>
                    <td><stripes:textarea id="previewContent" name="blogEntry.content" rows="20" style="width:100%;"/></td>
                </tr>
                <tr>
                    <td colspan="2">
                        <stripes:submit name="saveBlogEntry"><fmt:message key="blog_new_entry.jsp.saveBlogEntry"/></stripes:submit>
                        <stripes:submit name="publishBlogEntry"><fmt:message key="blog_new_entry.jsp.publishBlogEntry"/></stripes:submit>
                        <stripes:button id="preview" name="preview"><fmt:message key="blog_new_entry.jsp.preview"/></stripes:button>
                        <stripes:button id="commandHelp" name="commandHelp"><fmt:message key="blog_new_entry.jsp.commandHelp"/></stripes:button>
                    </td>
                </tr>
            </table>
        </stripes:form>
        </div>
        </jsecurity:hasPermission>
    </stripes:layout-component>
    
</stripes:layout-render>

